<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.sinodata.bsm.center.bean.ResTypeBean"%>
<%@page import="com.sinodata.bsm.center.bean.ResBean"%>
<%@page import="com.sinodata.bsm.center.cache.TopuConfCache"%>
<%@page import="com.sinodata.bsm.center.service.config.APPService"%>
<%@page import="com.sinodata.bsm.center.util.spring.SpringContextHolder"%>
<%@page import="com.sinodata.bsm.center.service.resource.ResService"%>
<%@ page import="com.sinodata.bsm.common.vo.*" %>
<%@ page import="com.sinodata.bsm.common.utils.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
String resid = request.getParameter("resid");
	/**
		主机：1101000000000|Unix主机:1101010000000/Windows主机:1101020000000
		数据库：1102000000000
		中间件_应用中间件：1103000000000
		中间件_消息中间件：1104000000000
		虚拟化：1108000000000
	*/
	List<Long> baseResTypes = new ArrayList<Long>();
	baseResTypes.add(1101000000000L);
	baseResTypes.add(1102000000000L);
	baseResTypes.add(1103000000000L);
	baseResTypes.add(1104000000000L);
	baseResTypes.add(1108000000000L);
	Map<Long,List<Res>> resMap  = new HashMap<Long,List<Res>>();
	for(Long resTypeId:baseResTypes){
	    resMap.put(resTypeId, new ArrayList<Res>());
	}
	ResBean resBean = ResBean.get(Long.valueOf(resid));
	ResBean[] resArray = resBean.children();
	for(ResBean bean:resArray){
	    ResTypeBean parentResTypeBean = bean.type().parent();
	    if(parentResTypeBean!=null){
	        ResType parentResType = parentResTypeBean.resType();
	        if(baseResTypes.contains(parentResType.getId())){
	            resMap.get(parentResType.getId()).add(bean.res());
	        }else{
	            ResTypeBean parentParentResTypeBean = parentResTypeBean.parent();
	            	if(parentParentResTypeBean!=null){
	            	    ResType parentParentResType = parentParentResTypeBean.resType();
	            	    if(baseResTypes.contains(parentParentResType.getId())){
	            	        resMap.get(parentParentResType.getId()).add(bean.res());
	            	    }
	            	}
	        }
	    }
	}
	APPService appService = SpringContextHolder.getBean(APPService.class);
	TopuConfCache topuConfCache = SpringContextHolder.getBean(TopuConfCache.class);
List<AppresTopoRel> appresTopoRelList = appService.getAllAppresTopoRel();
 List<AppresTopoRel> selectedList = new ArrayList<AppresTopoRel>();
  if(appresTopoRelList!=null&&appresTopoRelList.size()>0){
      for(AppresTopoRel appresTopoRel:appresTopoRelList){
         if( appresTopoRel.getResId()==Long.parseLong(resid) && appresTopoRel.getTab()==1){
             //TopuConf topuConf = topuConfCache.get(appresTopoRel.getTopuConfId());
             selectedList.add(appresTopoRel);
	         }
      }
  }
  AppresTopoRel[] arr = selectedList.toArray(new AppresTopoRel[selectedList.size()]);
  String ids = "";
  String link = "";
  for(int i=0; i<arr.length; i++){
      ids=arr[i].getTopuConfId().toString();
      TopuConf topuConf = topuConfCache.get(arr[i].getTopuConfId());
      for(int j=0; j<arr.length; j++){
          if(i!=j){
              ids+=","+arr[j].getTopuConfId().toString();
          }
      }
      link+="<p style='width:100%; padding:0px;'><a style='float:left; color:#091782; display:block; text-align:left; width:100%; height:18px; margin:3px 0px; text-indent:16px; background:url(../style/default/bsm/images/text-dian.png) no-repeat left center;' href='/bsm/resources/flash/BSTopoShowMain.html?topoId="+ids+"' target='_blank'>"+topuConf.getName()+"</a>";

  }

%>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />
	<%@ include file="../include/taglib.jsp"%>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/table.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<%@ include file="../include/tooltip.jsp"%>
<title>中科金财IT综合监控系统</title>
<link href="/bsm/style/default/bsm/tab.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/cluetip/jquery.cluetip.css" />
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/bsm/appviewdetail-view.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jcarousellite_1.0.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/charts/FusionCharts.js"></script>
<script type="text/javascript">
	function del(id){
		 $.ajax({
			   type: "POST", 
			   url: "${pageContext.request.contextPath}/appview/app!delete.action", //请求的action
			   data:{id:id}, //传的参数
			   dataType: 'json',
			   success: function(data){ //结果
				   window.location.reload();
			   }
		});
	}
$(document).ready(function() {
	initTop();
	initChart();
	var str = "<a href='/bsm/jsp/topo/topo-manage-main.jsp' target='_blank' style='color:blue;'>手机银行基础资源部署图</a>";
	//str += "<br><a href='/bsm/jsp/topo/topo-manage-main.jsp' target='_blank'>BSM系统部署图</a>";
	var topu = "<%=link%>";
	if(topu!=''){
		$.jBox.messager(topu, "基础架构拓扑图", null, { width: 200,timeout:0 });
	}
	$("#usability").hover(function (){
	    $("#next").show();
	    $("#prev").show();
	},function(){
	      $("#next").hide();
	      $("#prev").hide();
	   
	});
	
	$(".li_content2_bottom a").cluetip(
	     		{ 
     			  cluetipClass: 'jtip',
     			  arrows: true,
     			  dropShadow: false,
     			  hoverIntent: false,
     			  closePosition: 'title',
	     		  hoverClass: 'highlight',
	     		  mouseOutClose: true,
	  			  clickThrough:false,
	  			  ajaxCache: false
	 });
    $("#cate_more").toggle(function (){
     $("#toggle_down").show();
     $("#toggle_up").hide();
     $("#useability_div2").css("overflow","inherit");
     $("#useability_div1").css("height","auto");
     $("#useability_div2").css("height","auto");
     $("#useability_div1").css("overflow","inherit");
    },function(){
     $("#toggle_down").hide();
     $("#toggle_up").show();
     $("#useability_div1").css("height","150px");
     $("#useability_div2").css("height","150px");
     $("#useability_div1").css("overflow","hidden");
     $("#useability_div2").css("overflow","hidden");
  });
});

</script>
</head>
<body>
 <dlass="max">
  		<jsp:include page="viewdetailnewtop.jsp">
        	<jsp:param name="resid" value="<%=resid %>" ></jsp:param>
        	<jsp:param name="pageno" value="1" ></jsp:param>
         </jsp:include>
<div class="column">
          <!--主机-->
      <div class="left-div">
		  <b class="b1"></b>
		  <b class="b2"></b>
		  <b class="b3"></b>
		  <b class="b4"></b>  
		  <div class="content"> 
		    <h2>主机</h2>
			<div class="colD">		
				
			<%
	   		List<Res> hostList = resMap.get(1101000000000L);
	   		List<Res> databaseList = resMap.get(1102000000000L);
	   		List<Res> middlewareList = resMap.get(1103000000000L);
	   		middlewareList.addAll(resMap.get(1104000000000L));
	   		List<Res> virtulList = resMap.get(1108000000000L);
	   		int hostSize = hostList.size();
	   		int dbSize = databaseList.size();
	   		int addedhostSize=0;
	   		int addeddbSize=0;
	   		int addedmwSize = 0;
	   		int addedviSize = 0;
	   		int d = hostSize-dbSize;
	   		int d2 = middlewareList.size() - virtulList.size();
	   		if(d>0){
	   		    addeddbSize = Math.abs(d);
	   		}else if(d<0){
	   		    addedhostSize = Math.abs(d);
	   		}
	   		if(d2>0){
	   		    addedviSize = d2;
	   		}else if(d2<0){
	   		    addedmwSize = Math.abs(d2);
	   		}
	   		for(Res res:hostList){
	   	%>
	     <div class="por_div">
		 	<img src="/bsm/style/default/bsm/appview/s01.png"/>
			<a href="${pageContext.request.contextPath}/resource/res-query!view.action?id=<%=res.getId() %>&pId=0&viewId=1&ntype=2" target="_blank" ><p><%=res.getName() %></p><p><%=res.getIp() %></p></a>
			<a  class="Alarm"><img src="/bsm/style/default/tree/node/res<%=res.getHealthStatus() %>.png"/></a>		 
		 </div>
		 <%} 
	   		for(int i=0; i<addedhostSize; i++){
	   		    out.println(" <div class='por_div_nothing'></div>");
	   		}
	   		if(hostSize==0&&dbSize==0){
	   		    out.println(" <div class='por_div_nothing'></div>");
	   		}
		 %>
				 <br class="clear" />
 			</div>
	      </div>
		 </div>
		 <!--@end 主机-->
		 <!--数据库-->
    <div class="right-div">
		  <b class="b1"></b>
		  <b class="b2"></b>
		  <b class="b3"></b>
		  <b class="b4"></b>  
		  <div class="content"> 
		    <h2>数据库</h2>
		<div class="colD">	
		 <%
	   		for(Res res:databaseList){
	   	%>
	     <div class="por_div">
		 	<img src="/bsm/style/default/bsm/appview/database.png" />
			<a href="${pageContext.request.contextPath}/resource/res-query!view.action?id=<%=res.getId() %>&pId=0&viewId=1&ntype=2" target="_blank" ><p><%=res.getName() %></p><p><%=res.getIp() %></p></a>
			<a  class="Alarm"><img src="/bsm/style/default/tree/node/res<%=res.getHealthStatus() %>.png"/></a>		 
		 </div>
		 <%} 
	   	for(int i=0; i<addeddbSize; i++){
   		    out.println(" <div class='por_div_nothing'></div>");
   		}
	   	if(hostSize==0&&dbSize==0){
   		    out.println(" <div class='por_div_nothing'></div>");
   		}
		 %>
		<br class="clear" />
		</div>	
	      </div>
		 </div>
		 <!--@end 数据库-->
	</div>	 
<div class="column">
          <!--中间件/虚拟化-->
          <div class="left-div">
		  <b class="b1"></b>
		  <b class="b2"></b>
		  <b class="b3"></b>
		  <b class="b4"></b>  
		  <div class="content"> 
		    <h2>中间件</h2>
			<div class="colD">		
					 	<%
	   		for(Res res:middlewareList){
	   	%>
	     <div class="por_div">
		 	<img src="/bsm/style/default/bsm/appview/was.png" />
			<a href="${pageContext.request.contextPath}/resource/res-query!view.action?id=<%=res.getId() %>&pId=0&viewId=1&ntype=2" target="_blank" ><p><%=res.getName() %></p><p><%=res.getIp() %></p></a>
			<a class="Alarm"><img src="/bsm/style/default/tree/node/res<%=res.getHealthStatus() %>.png"/></a>		
		 </div>
		 <%} 
	   	for(int i=0; i<addedmwSize; i++){
   		    out.println(" <div class='por_div_nothing'></div>");
   		}
	   	if(middlewareList.size()==0&&virtulList.size()==0){
   		    out.println(" <div class='por_div_nothing'></div>");
   		}
		 %>
				 <br class="clear" />
 			</div>
	      </div>
		 </div>		 
		 
		 
		  <div class="right-div">
		  <b class="b1"></b>
		  <b class="b2"></b>
		  <b class="b3"></b>
		  <b class="b4"></b>  
		  <div class="content"> 
		    <h2>虚拟化</h2>
		
		<div class="colD">	
			<%for(Res res:virtulList){ %>
	     <div class="por_div">
		 	<img src="/bsm/style/default/bsm/appview/winpro.png" />
			<a href="${pageContext.request.contextPath}/resource/res-query!view.action?id=<%=res.getId() %>&pId=0&viewId=1&ntype=2" target="_blank" ><p><%=res.getName() %></p><p><%=res.getIp() %></p></a>
			<a  class="Alarm"><img src="/bsm/style/default/tree/node/res<%=res.getHealthStatus() %>.png"/></a>		
		 </div>
		 <%}
	   	for(int i=0; i<addedviSize; i++){
   		    out.println(" <div class='por_div_nothing'></div>");
   		}
	   	if(middlewareList.size()==0&&virtulList.size()==0){
   		    out.println(" <div class='por_div_nothing'></div>");
   		}
	   	%>
	

			<br class="clear" />
		    </div>	
	      </div>
		 </div>			 		 		 
       </div>
   <!--   </div> --> 
   </body>
</html>

